<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<form class="layui-form">
    <div class="layui-btn-container" style="position: absolute;left: 37%;bottom: 0;">
        <span class="layui-btn layui-btn-sm" id="importBtn">导入</span>
        <button class="layui-btn layui-btn-sm layui-btn-danger return">取消</button>
    </div>
    <table class="layui-table">
        <tr>
            <td style="background-color: #f3f3f3;">
                <label title="importFile">选择文件</label>
            </td>
            <td>
                <input type="file" id="importFile" name="importFile"/>
            </td>
        </tr>

        <tr>
            <td style="background-color: #f3f3f3;">
                <label title="">选择类型</label>
            </td>
            <td>
                <div class="layui-input-inline">
                    <input id='addImport' name='importType' type='radio' value="add" title="新增导入" checked=""/>
                    <input id='updateImport' name='importType' type='radio' value="update" title="更新导入"/>
                </div>
            </td>
        </tr>
    </table>
</form>
<script>
    var formKey = '${formKey}';
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'setter', 'upload', 'form', 'layer', 'commons'], function () {

        // -----常量声明----------
        var $ = layui.$,
            form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            setter = layui.setter,
            commons = layui.commons;

        var index = parent.layer.getFrameIndex(window.name);
        $('.return').click(function () {
            parent.layer.close(index);
        });
        var importType="add";
        form.on('radio',function (data) {
            importType=data.value;
        });
        //指定允许上传的文件类型
        upload.render({
            elem: '#importFile'
            , url: serverPath.formPath + setter.formLinkPath +'dataTemplate/importSave'
            , accept: 'file'
            , exts: 'xls|xlsx'
            , drag:true
            , auto: false //选择文件后不自动上传
            , bindAction: '#importBtn' //指向导入按钮触发上传
            , before: function (obj) {
                this.data = {"alias": formKey, "importType":importType};
            }
            , done: function (result) {
                if(result.code == 1){
                    return window.parent.layer.alert(result.msg);
                }else{
                    window.parent.layer.alert(result.msg, function (thisIndex) {

                        parent.layui.table.reload('templateTable',
                            {
                                page: {curr: 1}
                            });
                        parent.layui.totalFilter.init('templateTable');
                        commons._bulletWindow(thisIndex);
                        parent.layer.close(index);
                    });
                }
            }
            ,error:function(){
                layer.msg("文件导入失败！");
            }
        });

    })
</script>
</body>
</html>

